<?php
namespace app\admin\model\openservice;
use app\common\traits\ModelCurd;
use think\Model;

class OpenServiceApi extends Model
{
    use ModelCurd;
    protected $table = 'cp_oepnservice_api';

    /**
    * @Notes:获取分页节点
    * @User: chenping
    * @email: 375129701@qq.com
    * @param int $page
    * @param int $limit
    * @return $this[]|\think\Paginator
    */
    public function getPageNode($page=1,$limit=20)
    {
        return $this->paginate($limit);
    }

    /**
     * @Notes:获取全部节点
     * @User: chenping
     * @email: 375129701@qq.com
     * @return array|\PDOStatement|string|\think\Collection
     */
    public function getNodeList()
    {
        return $this->select();
    }

    /**
     * @Notes:清楚异常节点数据
     * @User: chenping
     * @email: 375129701@qq.com
     * @param $data
     * @return bool
     */
    public function clearExceptionNode($data)
    {
        $idList = [];
        foreach ($data as $k=>$v)
        {
            if($v['status']==0) array_push($idList,$v['id']);
        }
        if($idList)
        {
            return $this->whereIn("id",$idList)->delete();
        }else{
            return $idList;
        }
    }

    /**
     * @Notes:菜单节点相互转换
     * @User: chenping
     * @email: 375129701@qq.com
     * @param $id
     * @param $is_menu
     * @return static
     */
    public function isMenu($id,$is_menu)
    {
        return $this->update([
            "id"      => $id,
            "is_menu" => $is_menu
        ]);
    }

    /**
     * @Notes:权限控制
     * @User: chenping
     * @email: 375129701@qq.com
     * @param $id
     * @param $is_auth
     * @return static
     */
    public function isAuth($id,$is_auth)
    {
        return $this->update([
            "id"      => $id,
            "auth"    => $is_auth
        ]);
    }

    /**
     * @Notes:查找id节点
     * @User: chenping
     * @email: 375129701@qq.com
     * @param $id
     * @return $this
     */
    public function findNode($id)
    {
        return $this->find($id);
    }
}